package trism.game.components.actions {
	import trism.game.FlashVars;
	import trism.game.model.GameModel;

	import com.samoiloff.util.actions.LoadTextActionItem;

	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.net.URLRequest;

	/**
	 * @author Samoiloff  http://samoiloff.com/
	 */
	public class GameLoadConfigActionItem extends LoadTextActionItem {
		
		private var _model : GameModel;
		private var _fv : FlashVars;
		
		
		public function GameLoadConfigActionItem(model:GameModel) {
			_model = model;
			_fv = _model.commonItem.staticItem.flashvars;
			super();
		}

		override public function start() : void {
			_urlRequest = new URLRequest(_fv.configLink);
			super.start();
		}
		
		override protected function onError(event : ErrorEvent) : void {
			finish();
		}
		
		override protected function onLoadComplete(event : Event) : void {
			_fv.updateFromXml(new XML(event.target.data));
			finish();
		}
		
		
		override public function destroy() : void {
			_model = null;
			_fv = null;
			super.destroy();
		}
		

	}
}
